package com.wontube.media;

public final class BitConverterBE {
	public static long toUInt32(byte[] value, int startIndex) {
		long v = ((long)(value[startIndex] & 0xFF) << 24)
				| ((long)(value[startIndex + 1] & 0xFF) << 16)
				| ((long)(value[startIndex + 2] & 0xFF) << 8 )
				| ((long)value[startIndex + 3] & 0xFF);
		return v;
	}

	public static int toUInt16(byte[] value, int startIndex) {
		int v = ((value[startIndex] & 0xFF) << 8) | (value[startIndex + 1] & 0xFF);

		return v;
	}

	public static byte[] getLongBytes(long value) {
		byte[] buff = new byte[8];
		buff[0] = (byte) (value >> 56);
		buff[1] = (byte) (value >> 48);
		buff[2] = (byte) (value >> 40);
		buff[3] = (byte) (value >> 32);
		buff[4] = (byte) (value >> 24);
		buff[5] = (byte) (value >> 16);
		buff[6] = (byte) (value >> 8);
		buff[7] = (byte) (value);
		
		return buff;
	}

	public static byte[] getBytes(long value) {
		byte[] buff = new byte[4];
		buff[0] = (byte) (value >>> 24);
		buff[1] = (byte) (value >>> 16);
		buff[2] = (byte) (value >>> 8);
		buff[3] = (byte) (value);
		
		return buff;
	}

	public static byte[] getBytes(int value) {
		byte[] buff = new byte[2];
		buff[0] = (byte) (value >>> 8);
		buff[1] = (byte) (value);
		
		return buff;
	}
}
